/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024.
 * Description: Enhancements related to RTOS hangtask
 * Author: zhousiqi
 * Create: 2023-9-25
 */

#include <linux/ktime.h>
#include <linux/printk.h>
#include "rtos_hung_task.h"

#ifdef CONFIG_RTOS_HUNGTASK_TIMES
/*
 * Describe the in & out time for hungtask task through this macro
 */
#define HSNUM	2
static unsigned int cur_index;
static unsigned long hungtask_time[HSNUM];

void set_hungtask_entry_time(void)
{
	hungtask_time[cur_index % HSNUM] = ktime_get_seconds();
	cur_index++;
}

void show_hungtask_entry_times(void)
{
	pr_info("start at %lus, and end at %lus\n",
		hungtask_time[cur_index % HSNUM],
		hungtask_time[(cur_index + 1) % HSNUM]);
}
#endif

#ifdef CONFIG_RTOS_SUPPORT_PRIVATE_HUNGTASK
/*
 * Some products rewrite the hungtask check based on the kernel hungtask mechanism
 * To avoid interference and conflict, an interface is provided to disable the
 * kernel hungtask check.
 */
bool linus_hungtask_enable = true;
void disable_linus_hungtask_check(void)
{
	linus_hungtask_enable = false;
}
EXPORT_SYMBOL_GPL(disable_linus_hungtask_check);

void enable_linus_hungtask_check(void)
{
	linus_hungtask_enable = true;
}
EXPORT_SYMBOL_GPL(enable_linus_hungtask_check);
#endif
